#include <iostream>

class person;

class dog{
public:
    person *p;

    dog();
    void bite();
};

class person{
    // 全局函数友元,可以访问类里面的私有成员
    friend void function1(person *p);
    
    friend class box;
    // friend class dog;
    friend void dog::bite();

private:
    int id;
public:
    std::string name;
    person() : id(20), name("wan"){}
};

// 友元类
class box{
public:
    person *p;

    box();
    void loding();
};


box::box(){
    p = new person;
}

void box::loding(){
    std::cout<< "box loding person id:"<< p->id << std::endl;   //友元类访问类中的私有属性
    std::cout<< "box loding person name:"<< p->name << std::endl;
}


dog::dog(){
    p = new person;
}
void dog::bite(){
    std::cout<< "bite person:"<< p->id << std::endl;
    std::cout<< "bite person:"<< p->name << std::endl;
}


void function1(person *p){
    std::cout<< "person :"<< p->id << std::endl;    //友元全局函数访问类里面的私有成员
    std::cout<< "person :"<< p->name << std::endl;
}

int main()
{
    person p1;
    function1(&p1);

    box b1;
    b1.loding();

    dog d1;
    d1.bite();

    return 0;
}